<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title><?php echo $this->translate('order detail'); ?>: <?php echo $this->order['name']; ?></title>
    <script src='<?php echo $this->templateURL; ?>/js/jquery.js' type="text/javascript"></script>
    <script src='<?php echo $this->templateURL; ?>/js/jquery-ui-1.10.3.custom.min.js' type="text/javascript"></script>
    <link href="<?php echo $this->templateURL; ?>/css/jquery-ui-1.10.3.custom.css" rel="stylesheet" />
    <style>
        body{
            
        }
        
        table{
            width: 800px;
            margin: auto;
            border-collapse:collapse;
            -webkit-print-color-adjust:exact;
        }
        
        thead{
            z-index: 999;
            background-color: #ffffff !important;
        }
        
        tbody{
            border: 1px solid black;
        }
        
        tbody td{
            border: 1px solid black;
            padding: 4px 0;
            font-size: 20px;
        }
        
        table th{
            text-align: left;
            font-size: 16px;
            font-weight: 100;
        }
        
        table th.title{
            text-align: center;
            font-weight: bold;
            vertical-align: bottom;
            font-size: 18pt;
            padding: 7px 0;
        }
        
        table th.customer-info{
            width: 250px;
            text-transform: capitalize;
        }
        
        table tr.ptitle td{
            font-size: 17px !important;
        }
        
        table tr.ptitle td{
            font-weight: bold;
            text-align: center;
            text-transform: uppercase;
            font-size: 16px;
        }
        
        table tr td{
            text-align: center;
            font-size: 20px;
        }
        
        table tbody tr td.pname{
            text-align: left;
            text-transform: capitalize;
        }
        
        table tbody tr td.ptotal, table tbody tr td.pprice{
            text-align: right;
            padding-right: 5px;
        }
        
        table tbody tr td.ptotal, table tbody tr td.pquantity{
            font-weight: bold;
        }
        
        table tbody tr td.pbrand{
            text-transform: capitalize;
            font-weight: bold;
        }
        
        .writer{
            text-align: center;
        }
        
        .number{
            text-align: right;
            font-weight: bold;
        }
        
        .date{
            text-align: center;
            font-weight: bold;
        }
        
        .disable{
            display: none;
        }
        
        .right{
            text-align: right;
        }
        
        tfoot .right,tfoot  .number{
            font-size: 22px;
        }
        
        body{
            height: auto !important;
        }
        
        table tr.odd td{
            background-color: #e9e9e9;
            -webkit-print-color-adjust:exact;
        }
        
        .buttonBar{
            position: fixed;
            top: 10px;
            left: 50px;
            z-index: 1;
        }
        
        .buttonBar button{
            font-size: 16px;
        }
        
        @media print{
            table tr.odd td{
                background-color: #e9e9e9;
                -webkit-print-color-adjust:exact;
            }
            
            body, span, div, table, tr, tbody, tfoot, td, hr { 
                -webkit-print-color-adjust: exact !important;
            }
            
            .buttonBar{
                display: none;
            }
        }
    </style>
</head>

<body>
<div class="buttonBar">
<button id="print" type="button">
    <?php echo $this->translate('print'); ?>
</button>
<button id="close" type="button">
    Đóng
</button>
<p>Chỉnh kích thước chữ:</p>
<div id="slider"></div>
<strong id="fontSize"></strong>
</div>
<table id="printTable" tabindex="1">
    <thead>
        <tr>
            <th colspan="4">
                CÔNG TY TNHH SX-TM MP HÂN VY<br />
                Địa chỉ: 35 Tam Hà, Phường Tam Phú, Quận Thủ Đức, TPHCM<br />
                Điện Thoại: (84-8) 3.986.1237 - Fax: (84-8) 3.729.6239<br />
                Điện Thoại tư vấn: 0973.479.839 - 0938.798.876
            </th>
            <th colspan="3" class="customer-info">
                <strong><span style="font-size: 26px;"><?php echo $this->order['name']; ?></span></strong><br />
                <!--Địa chỉ: <?php echo $this->order['address']; ?><br />
                Điện thoại: <?php echo $this->order['phone_number']; ?><br />-->
                Ngày: <?php echo date("d-m-Y", strtotime($this->order['date'])); ?><br />
                HĐ Số: <?php echo $this->order['id']; ?>
            </th>
        </tr>
        <tr>
            <th colspan="7" class="title">
                HÓA ĐƠN GỞI HÀNG
                <br />
            </th>
        </tr>
    </thead>
    
    <tfoot>
        <tr>
            <td style="text-align: left;" colspan="7">
                <br />
            </td>
        </tr>
        <?php if($this->order['discount'] == 0): ?>
        <tr>
            <td class="writer" colspan="2">
                Người viết hóa đơn
            </td>
            <td class="right" colspan="2">Tổng cộng:</td>
            <td class="number" colspan="2"><?php echo number_format($this->order['subtotal']); ?></td>
        </tr>
        <?php else: ?>
        <tr>
            <td class="writer" colspan="2">
                Người viết hóa đơn
            </td>
            <td class="right" colspan="2">Giá chưa chiết khấu:</td>
            <td class="number" colspan="2"><?php echo number_format($this->order['totalprice']); ?></td>
        </tr>
        <!--<tr>
            <td class="writer" colspan="2"></td>
            <td class="right" colspan="2">Chiết khấu:</td>
            <td class="number" colspan="2"><?php echo number_format($this->order['discount']); ?>%</td>
        </tr>-->
        <tr>
            <td class="writer" colspan="2"></td>
            <td class="right" colspan="2">Giá đã chiết khấu:</td>
            <td class="number" colspan="2"><?php echo number_format($this->order['subtotal']); ?></td>
        </tr>
        <?php endif; ?>
        <tr>
            <td colspan="2"></td>
            <td class="right" colspan="2">Nợ cũ:</td>
            <td class="number" colspan="3"><?php echo number_format($this->order['dept']); ?></td>
        </tr>
        <tr>
            <td colspan="2"></td>
            <td class="right" colspan="2">Thanh toán:</td>
            <td class="number" colspan="3"><?php echo number_format($this->order['totalpay']); ?></td>
        </tr>
        <tr>
            <td colspan="2"></td>
            <td class="right" colspan="2">Trả hàng:</td>
            <td class="number" colspan="3"><?php echo number_format($this->order['refund']); ?></td>
        </tr>
        <tr>
            <td class="writer" colspan="2">Thanh Khương</td>
            <td class="right" colspan="2">Còn lại:</td>
            <td class="number" colspan="3"><?php echo number_format($this->order['remaining']); ?></td>
        </tr>
    </tfoot>
    
    <tbody>
        <tr class="ptitle">
            <td>
                <?php echo $this->translate('product name'); ?>
            </td>
            <td style="width: 7%;">
                <?php echo $this->translate('net'); ?>
            </td>
            <td>
                <?php echo $this->translate('T.Hiệu'); ?>
            </td>
            <td style="width: 7%;">
                <?php echo $this->translate('SL'); ?>
            </td>
            <td style="width: 10%;">
                <?php echo $this->translate('pprice'); ?>
            </td>
            <td style="width: 15%;">
                <?php echo $this->translate('ptotal'); ?>
            </td>
        </tr>
        <?php foreach($this->products as $product): ?>
        <tr>
            <td class="pname">
                &nbsp;<?php echo $product['name']; ?>
            </td>
            <td class="pnet">
                <?php echo $product['net']; ?>
            </td>
            <td class="pbrand">
                <?php echo $product['brand']; ?>
            </td>
            <td class="pquantity">
                <?php echo $product['quantity']; ?>
            </td>
            <td class="pprice">
                <?php
                    $price = $product['price'];
                    
                    /*if($product['discount_type']){
                        $price = $price * (1 - ($product['discount'] / 100));
                    }else{
                        $price = $price - $product['discount'];
                    }*/
                ?>
                <?php echo number_format($price); ?>
            </td>
            <td class="ptotal">
                <?php echo number_format($product['total']); ?>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
</body>
</html>
<script>
$(document).ready(function(){
    function printPage(){
        $(".buttonBar").addClass('disable');
        window.print();
        $(".disable").removeClass('disable');
    }
    
    $("tbody tr:odd").addClass("odd");
    
    $("#print").click(function(){
        printPage();
    });
    
    $("#close").click(function(){
        window.close();
    });
    
    //printPage();
});

$(function() {
    $("#fontSize").html("20");
    $( "#slider" ).slider({
        min: 10,
        max: 50,
        value: 20,
        step: 1,
        slide: function(event, ui){
            var size = ui.value;
            $("tbody td").css("font-size", size);
            $("tfoot td").css("font-size", size + 2);
            $("#fontSize").html(size);
        }
    });
});
</script>